<?php

declare(strict_types=1);

namespace app\operations\model;

use sheep\model\Common;

class WalletLog extends Common
{
    protected $name = 'store_wallet_log';
    protected $type = [
        'ext' => 'json'
    ];
    // 追加属性
    protected $append = [
        'event_text'
    ];

    const TYPE_MAP = [
        'money' => '余额',
    ];

    protected $eventMap = [
        'money' => [
            'admin_recharge' => '后台-余额充值',
        ],
    ];


    public function scopeMoney($query)
    {
        return $query->where('type', 'money');
    }


    public function getEventTextAttr($value, $data)
    {
        return $this->eventMap[$data['type']][$data['event']] ?? '';
    }

    public function oper()
    {
        return $this->morphTo(['oper_type', 'oper_id'], [
            'user' => \sheep\model\user\User::class,
            'admin' => \sheep\model\auth\Admin::class,
            'system' => \sheep\model\auth\Admin::class,
        ]);
    }
}
